// LineDisplay.h : Declaration of the CLineDisplay

#pragma once
#include "resource.h"       // main symbols
#include "LineDisplaySO_i.h"
#include "LogUtil.h"


#if defined(_WIN32_WCE) && !defined(_CE_DCOM) && !defined(_CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA)
#error "Single-threaded COM objects are not properly supported on Windows CE platform, such as the Windows Mobile platforms that do not include full DCOM support. Define _CE_ALLOW_SINGLE_THREADED_OBJECTS_IN_MTA to force ATL to support creating single-thread COM object's and allow use of it's single-threaded COM object implementations. The threading model in your rgs file was set to 'Free' as that is the only threading model supported in non DCOM Windows CE platforms."
#endif

#include "LineDisplayImp.h"

// CLineDisplay

class ATL_NO_VTABLE CLineDisplay :
	public CComObjectRootEx<CComSingleThreadModel>,
	public CComCoClass<CLineDisplay, &CLSID_LineDisplay>,
	public IDispatchImpl<ILineDisplay, &IID_ILineDisplay, &LIBID_LineDisplaySOLib, /*wMajor =*/ 1, /*wMinor =*/ 0>
{
public:
	CLineDisplay();

	DECLARE_REGISTRY_RESOURCEID(IDR_LINEDISPLAY)


	BEGIN_COM_MAP(CLineDisplay)
		COM_INTERFACE_ENTRY(ILineDisplay)
		COM_INTERFACE_ENTRY(IDispatch)
	END_COM_MAP()



	DECLARE_PROTECT_FINAL_CONSTRUCT()

	HRESULT FinalConstruct()
	{
		using namespace Utility::LoggerLib;
		if (!IsLogInitialized())
		{
			InitLogger();
		}
		return S_OK;
	}

	void FinalRelease()
	{
		if (NULL != m_pLD)
		{
			delete m_pLD;
			m_pLD = NULL;
		}
	}

public:
	// Methods
	// Release 1.0 ~1.5
	STDMETHOD(Claim)(LONG Timeout, /*[out,retval]*/LONG *pRC);
	STDMETHOD(CloseService)(/*[out,retval]*/LONG *pRC);
	STDMETHOD(SetDescriptor)(LONG Descriptor,LONG Attribute,/*[out,retval]*/LONG* pRC);
	STDMETHOD(ScrollText)(LONG Direction,LONG Units,/*[out,retval]*/LONG* pRC);
	STDMETHOD(RefreshWindow)(LONG Window,/*[out,retval]*/LONG* pRC);
	STDMETHOD(DisplayTextAt)(LONG Row,LONG Column,BSTR Data,LONG Attribute,/*[out,retval]*/LONG* pRC);
	STDMETHOD(DisplayText)(BSTR Data,LONG Attribute,/*[out,retval]*/LONG *pRC);
	STDMETHOD(DestroyWindow)(/*[out,retval]*/LONG* pRC);
	STDMETHOD(ClearText)(/*[out, retval]*/LONG *pRC);
	STDMETHOD(ClearDescriptors)(/*[out, retval]*/LONG *pRC);
	STDMETHOD(GetOpenResult)(/*[out,retval]*/LONG* pRC);
	STDMETHOD(ReleaseDevice)(/*[out,retval]*/LONG* pRC);
	STDMETHOD(DirectIO)(LONG Command,/*[in,out]*/LONG *pData,/*[in,out]*/BSTR* pString,/*[out,retval]*/LONG *pRC);
	STDMETHOD(Close)(/*[out,retval]*/LONG *pRC);
	STDMETHOD(ClaimDevice)(LONG Timeout,/*[out,retval]*/LONG* pRC);
	STDMETHOD(CheckHealth)(LONG Level,/*[out,retval]*/LONG* pRC);
	STDMETHOD(OpenService)(BSTR DeviceClass,BSTR DeviceName,IDispatch* pDispatch,/*[out,retval]*/LONG* pRC);
	STDMETHOD(SetPropertyString)(LONG PropIndex,BSTR String);
	STDMETHOD(GetPropertyString)(LONG PropIndex,/*[out,retval]*/BSTR* pString);
	STDMETHOD(SetPropertyNumber)(LONG PropIndex,LONG Number);
	STDMETHOD(GetPropertyNumber)(LONG PropIndex,/*[out,retval]*/LONG *pNumber);
	STDMETHOD(COFreezeEvents)(VARIANT_BOOL Freeze,/*[out,retval]*/LONG* pRC);
	STDMETHOD(CreateWindow)(LONG ViewportRow,LONG ViewportColumn,LONG ViewportHeight,LONG ViewportWidth,LONG WindowHeight,LONG WindowWidth,/*[out,retval]*/LONG* pRC);

	// Release 1.6
	STDMETHOD(DefineGlyph)(LONG GlyphCode, BSTR Gryph, LONG *pRC);
	STDMETHOD(ReadCharacterAtCursor)(LONG *pChar, LONG *pRC);
	
	// Release 1.7
	STDMETHOD(DisplayBitmap)(BSTR FileName, LONG Width, LONG AlignmentX, LONG AlignmentY, LONG *pRC);
	STDMETHOD(SetBitmap)(LONG BitmapNumber, BSTR FileName, LONG AlignmentX, LONG AlignmentY, LONG *pRC);

	// Release 1.8
	STDMETHOD(ResetStatistics)(BSTR StatisticsBuffer, LONG *pRC);
	STDMETHOD(RetrieveStatistics)(BSTR *pStatisticsBuffer, LONG *pRC);
	STDMETHOD(UpdateStatistics)(BSTR StatisticsBuffer, LONG *pRC);

	// Release 1.9
	STDMETHOD(CompareFirmwareVersion)(BSTR FirmwareFileName, LONG *pResult, LONG *pRC);
	STDMETHOD(UpdateFirmware)(BSTR FirmwareFileName, LONG *pRC);

	// Release 1.10
	STDMETHOD(ClearInputProperties)(LONG *pRC);

private:
	LineDisplayImp::CLineDisplayImp* GetInstance(const CString &strDeviceName);

private:
	BOOL m_bOpened;
	BOOL m_bClaimed;
	BOOL m_bEnabled;
	LONG m_error;

	LineDisplayImp::CLineDisplayImp *m_pLD;

	CString m_strDevName;
	CString m_strDevDescription;
	
	LONG m_lOpenResult;
	LONG m_lState;
	LONG m_lResultCode;

};

OBJECT_ENTRY_AUTO(__uuidof(LineDisplay), CLineDisplay)
